/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var findKthLargest = function(nums, k) {
  function quickSort(left, right) {
    if(left >= right)
      return;
    let i = left, j = right, base = nums[left];
    while(i < j) {
      while(i < j && nums[j] >= base) j--;
      while(i < j && nums[i] <= base) i++;
      if(i < j) {
        let temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
      }
    }
    nums[left] = nums[i];
    nums[i] = base;
    quickSort(left, i);
    quickSort(j + 1, right);
  }
  quickSort(0, nums.length - 1);
  return nums[nums.length - k];
};
let nums = [3,2,1,5,6,4], k = 2;
console.log(findKthLargest(nums, k));
nums = [3,2,3,1,2,4,5,5,6], k = 4;
console.log(findKthLargest(nums, k));
